<template>
  <div>
    <div class="i-layout-page-header">
      <div class="i-layout-page-header">
        <span class="ivu-page-header-title">宽带管理</span>
      </div>
    </div>
    <Card :bordered="false" dis-hover class="ivu-mt">
      <Form
        ref="artFrom"
        :model="artFrom"
        :label-width="labelWidth"
        :label-position="labelPosition"
        @submit.native.prevent
      >
        <Row type="flex" :gutter="24">
          <Col v-bind="grid">
            <FormItem label="搜索：" label-for="title">
              <Input
                search
                enter-button
                placeholder="请输入"
                v-model="artFrom.title"
                style="width: 80%"
                @on-search="userSearchs"
              />
            </FormItem>
          </Col>
        </Row>
		<Row type="flex" :gutter="24">
			<Col span="24">
			  <div class="ml20">
			    <!-- <Button v-auth="['order-dels']" class="mr10" type="primary" @click="delAll">批量删除订单</Button> -->
			    <!-- <Button v-auth="['order-write']" type="success" class="mr10 greens" size="default" @click="writeOff">
			      <Icon type="md-list"></Icon>
			      订单核销
			    </Button> -->
			    <Button class="export" icon="ios-share-outline" @click="exports">导出</Button
			    >
			  </div>
			</Col>
		</Row>
      </Form>
      <Table
        :columns="columns1"
        :data="cmsList"
        ref="table"
        class="mt25"
        :loading="loading"
        highlight-row
        no-userFrom-text="暂无数据"
        no-filtered-userFrom-text="暂无筛选结果"
      >
        <template slot-scope="{ row, index }" slot="titles">
          <span>{{ ' [ ' + row.catename + ' ] ' + row.title }}</span>
        </template>
        <template slot-scope="{ row, index }" slot="cover">
          <div v-if="row.cover.length !== 0" v-viewer>
            <div class="tabBox_img">
              <img v-lazy="row.cover" />
            </div>
          </div>
        </template>
        <template slot-scope="{ row, index }" slot="action">
          <a @click="edit(row)">编辑</a>
		  <Divider type="vertical" />
          <a @click="del(row, '删除门店', index)">删除</a>
        </template>
		<template slot-scope="{ row, index }" slot="status">
		  <span v-if="row.status == 0">待审核</span>
		  <span v-if="row.status == 1">已通过</span>
		  <span v-if="row.status == 2">未通过</span>
		  <span v-if="row.status == 3">已过期</span>
		</template>
      </Table>
      <div class="acea-row row-right page">
        <Page
          :total="total"
          :current="artFrom.page"
          show-elevator
          show-total
          @on-change="pageChange"
          :page-size="artFrom.limit"
        />
      </div>
    </Card>
    <!--关联-->
    
    <Modal
      v-model="modals"
      title="导出数据"
      class="paymentFooter"
      scrollable
      width="350"
      @on-cancel="cancel"
    >
    	<Form
    	  class="form"
    	  ref="formValidate"
    	  :label-width="labelWidth"
    	  :label-position="labelPosition"
    	  @submit.native.prevent
    	>
    		<Row :gutter="24" type="flex">
    		  <Col>
    			
    			  <FormItem label="结束时间：" prop="end_time" label-for="end_time">
    			    <DatePicker
    				:editable="false"
    				@on-change="onchangeStartTime"
    				:value="start_time"
    				format="yyyy-MM-dd HH:mm"
    				type="datetime"
    				placement="bottom-end"
    				placeholder="请选择时间"
    				style="width: 100%"
    			    ></DatePicker>
    			  </FormItem>
    		  </Col>
    		</Row>
    		<Row :gutter="24" type="flex">
    		  <Col>
    			
    			  <FormItem label="结束时间：" prop="end_time" label-for="end_time">
    				  <DatePicker
    					:editable="false"
    					@on-change="onchangeEndTime"
    					:value="end_time"
    					format="yyyy-MM-dd HH:mm"
    					type="datetime"
    					placement="bottom-end"
    					placeholder="请选择时间"
    					style="width: 100%"
    				  ></DatePicker>
    			  </FormItem>
    		  </Col>
    		</Row>
    	</Form>
    	<div slot="footer">
    	  <Button @click="cancelExport()">取消</Button>
    	  <Button type="primary" @click="exportEvent()">立即导出</Button>
    	</div>
    </Modal>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import { cmsListApi ,brandExportApi} from '@/api/req';
import relationList from './relation';
import { formatDate } from '@/utils/validate';
import goodsList from '@/components/goodsList/index';
export default {
  name: 'addStore',
  data() {
    return {
      modalTitleSs: '',
      currentTab: '',
      grid: {
        xl: 8,
        lg: 8,
        md: 12,
        sm: 24,
        xs: 24,
      },
      loading: false,
      artFrom: {
        pid: 0,
        title: '',
        page: 1,
        limit: 20,
		status:3
      },
      total: 0,
      columns1: [
        {
          title: 'ID',
          key: 'id',
          width: 50,
        },
        {
          title: '申请时间',
          key: 'created_time',
          minWidth: 90,
		  align:'center'
        },
        {
          title: '姓名',
          key: 'name',
          minWidth: 50,
		  align:'center'
        },
        {
          title: '加入时间',
          key: 'join_time',
          minWidth: 50,
		  align:'center'
        },
        {
          title: '安装地址',
          key: 'address',
          minWidth: 130,
        },
        {
          title: '手机号码',
          key: 'phone',
          minWidth: 80,
		  align:'center'
        },
        {
          title: '使用期限',
          key: 'use_time',
          minWidth: 80,
		  align:'center'
        },
        {
          title: '状态',
          slot: 'status',
          minWidth: 80,
		  align:'center'
        },
        {
          title: '开始时间',
          key: 'start_time',
          minWidth: 80,
		  align:'center'
        },
        {
          title: '结束时间',
          key: 'end_time',
          minWidth: 80,
		  align:'center'
        },
        {
          title: '审核人',
          key: 'user_name',
          minWidth: 80,
		  align:'center'
        },
        {
          title: '审核时间',
          key: 'audi_time',
          minWidth: 80,
		  align:'center'
        },
        // {
        //   title: '操作',
        //   slot: 'action',
        //   fixed: 'right',
        //   minWidth: 150,
        // },
      ],
      cmsList: [],
      treeData: [],
      list: [],
      cid: 0, // 移动分类id
      cmsId: 0,
      formValidate: {
        type: 1,
      },
      rows: {},
      modal_loading: false,
      modals: false,
	  start_time:'',
	  end_time:'',
    };
  },
  components: {
    relationList,
    goodsList,
  },
  computed: {
    ...mapState('media', ['isMobile']),
    labelWidth() {
      return this.isMobile ? undefined : 75;
    },
    labelPosition() {
      return this.isMobile ? 'top' : 'right';
    },
  },
  created() {
	  console.info("执行created")
    this.artFrom.pid = this.$route.query.id ? this.$route.query.id : 0;
    this.getList();
  },
  activated() {
	  console.info("执行")
  },
  methods: {
	  
	exports(){
		this.start_time = '';
		this.end_time = '';
		this.modals = true;
	},
	cancelExport(){
		this.modals = false;
	},
	exportEvent(){
		  brandExportApi({
			  status:3,
			  start_time:this.start_time,
			  end_time:this.end_time
		  })
		    .then((res) => {
				window.open(res.data[0]);
		    })
		    .catch((res) => {
		      this.$Message.error(res.msg);
		    });
		this.modals = false;
	},
	onchangeStartTime(e){
		this.start_time = e;
	},
	onchangeEndTime(e){
		this.end_time = e;
	},
    // 关联成功
    getProductId(row) {
      
    },
    cancel() {
      this.modals = false;
    },
    // 等级列表
    getList() {
      this.loading = true;
      cmsListApi(this.artFrom)
        .then(async (res) => {
          let data = res.data;
          this.cmsList = data.list;
          this.total = data.count;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
          this.$Message.error(res.msg);
        });
    },
    pageChange(index) {
      this.artFrom.page = index;
      this.getList();
    },
    // 下拉树
    handleCheckChange(data) {
      let value = '';
      let title = '';
      this.list = [];
      this.artFrom.pid = 0;
      data.forEach((item, index) => {
        value += `${item.id},`;
        title += `${item.title},`;
      });
      value = value.substring(0, value.length - 1);
      title = title.substring(0, title.length - 1);
      this.list.push({
        value,
        title,
      });
      this.artFrom.pid = value;
      this.artFrom.page = 1;
      this.getList();
    },
    // 编辑
    edit(row) {
      this.$router.push({ path: '/admin/repair/add_store/' + row.id });
    },
    // 关联
    artRelation(row, tit, num) {
      this.rows = row;
      if (row.product_id === 0) {
        this.modals = true;
      } else {
        let delfromData = {
          title: tit,
          num: num,
          url: `/cms/cms/unrelation/${row.id}`,
          method: 'PUT',
          ids: '',
        };
        this.$modalSure(delfromData)
          .then((res) => {
            this.$Message.success(res.msg);
            this.getList();
          })
          .catch((res) => {
            this.$Message.error(res.msg);
          });
      }
    },
    // 删除
    del(row, tit, num) {
      let delfromData = {
        title: tit,
        num: num,
        url: `store/store/${row.id}`,
        method: 'DELETE',
        ids: '',
      };
      this.$modalSure(delfromData)
        .then((res) => {
          this.$Message.success(res.msg);
          this.cmsList.splice(num, 1);
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
    // 表格搜索
    userSearchs() {
      this.artFrom.page = 1;
      this.getList();
    },
  },
};
</script>

<style scoped lang="stylus">
.treeSel >>>.ivu-select-dropdown-list {
  padding: 0 10px !important;
  box-sizing: border-box;
}

.tabBox_img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  cursor: pointer;

  img {
    width: 100%;
    height: 100%;
  }
}
</style>
